2020-2021 Sunseeker Telemetry and Lighting System
hspll_ex1_output_ussxtosc.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // hspll_ex1_output_ussxtosc.c - Output USSXT OSC at 8MHz on a pin.
34 //
35 // Description: Configure USSXT = 8MHz and output on a pin. This can be used
36 // for monitoring the clock or use the clock as the source of another subsystem.
37 //
38 // MSP430FR6047
39 // ---------------
40 // /|\| |
41 // | | |
42 // --|RST |
43 // | P1.0|---> LED
44 // | |-USSXTIN
45 // | |-USSXTOUT
46 // | P8.7|---> USSXT_BOUT (8MHz)
47 //
48 // Wallace Tran
49 // Texas Instruments Inc.
50 // June 2017
51 //******************************************************************************
52 #include "driverlib.h"
53 
54 void main(void)
55 {
56  // Stop WDT
57  WDT_A_hold(WDT_A_BASE);
58 
59  // Configure P8.7 as USSXT_BOUT
60  GPIO_setAsPeripheralModuleFunctionOutputPin(
61  GPIO_PORT_P8,
62  GPIO_PIN7,
63  GPIO_SECONDARY_MODULE_FUNCTION
64  );
65 
66  // Configure P1.0 as output for LED
67  GPIO_setAsPeripheralModuleFunctionOutputPin(
68  GPIO_PORT_P1,
69  GPIO_PIN0,
70  GPIO_PRIMARY_MODULE_FUNCTION
71  );
72 
73  // Disable the GPIO power-on default high-impedance mode to activate
74  // previously configured port settings
75  PMM_unlockLPM5();
76 
77  // Clock System Setup
78  // Set DCO to 8MHz
79  CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);
80  // Set SMCLK = MCLK = DCO, ACLK = VLOCLK
81  // MCLK = SMCLK = 1MHz
82  CS_initClockSignal(CS_ACLK, CS_VLOCLK_SELECT, CS_CLOCK_DIVIDER_1);
83  CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
84  CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
85 
86  // Configure USSXT Oscillator
87  HSPLL_xtalInitParam param = {0};
88  param.oscillatorType = HSPLL_XTAL_OSCTYPE_XTAL;
89  param.oscillatorEnable = HSPLL_XTAL_ENABLE;
90  param.xtlOutput = HSPLL_XTAL_OUTPUT_ENABLE;
91  HSPLL_xtalInit(HSPLL_BASE, &param);
92 
93  // Check if oscillator is stable
94  while(HSPLL_getOscillatorStatus(HSPLL_BASE) == HSPLL_OSCILLATOR_NOT_STABILIZED);
95 
96  // Set up timer to wait in LPM for crystal stabilization time = 4096 clocks for crystal resonator.
97  // For 8MHz XTAL, 4096 clocks = 512us. Using VLO = 9.4kHz, wait 5 timer clock cycles = 532us.
98  Timer_A_initUpModeParam timerParam = {0};
99  timerParam.timerPeriod = 5;
100  timerParam.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
101  // Timer sourced from ACLK (VLO)
102  timerParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
103  // Clear timer
104  timerParam.timerClear = TIMER_A_DO_CLEAR;
105  timerParam.startTimer = true;
106  Timer_A_initUpMode(TA4_BASE, &timerParam);
107 
108  // Enter LPM3 w/interrupts enabled
109  __bis_SR_register(LPM3_bits | GIE);
110 
111  // For debugger
112  __no_operation();
113 
114  while(1)
115  {
116  // Toggle LED to show oscillator init complete
117  GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
118  // Wait 100,000 CPU cycles
119  __delay_cycles(50000);
120  }
121 }
122 
123 // Timer A4 interrupt service routine
124 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
125 #pragma vector = TIMER4_A0_VECTOR
126 __interrupt void Timer4_A0_ISR(void)
127 #elif defined(__GNUC__)
128 void __attribute__ ((interrupt(TIMER4_A0_VECTOR))) Timer4_A0_ISR (void)
129 #else
130 #error Compiler not supported!
131 #endif
132 {
133  // Stop the timer and wake up from LPM
134  Timer_A_startCounter(TA4_BASE, TIMER_A_STOP_MODE);
135  __bic_SR_register_on_exit(LPM3_bits | GIE);
137 }
MPU_initThreeSegmentsParam param
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
void main(void)
__delay_cycles(500000)